import request from './index'
// 是否全局消息提示
const requestOptions = {
  globalErrorMessage: true,
  globalSuccessMessage: true
}

// 获取商品列表
export function getRightsList(data?: any) {
  return request.get(`goods?condition=${data.condition}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`, {
    requestOptions
  })
}

// 添加商品
export function createGood(data?: any) {
  return request.post('goods', data, { requestOptions })
}

// 更新商品
export function updateGood(data?: any) {
  return request.put(`goods/${data.id}`, data, {
    requestOptions
  })
}

// 删除商品
export function delGood(data?: any) {
  return request.delete(`goods/${data.id}`, {
    requestOptions
  })
}

// 获取商品详情
export function getGoodById(data?: any) {
  return request.get(`goods/${data.id}`, {
    requestOptions
  })
}

// 更新商品的图片
export function updateGoodPics(data?: any) {
  return request.put(`goods/${data.id}/pics`, data, {
    requestOptions
  })
}

// 更新商品的属性
export function updateGoodAttrs(data?: any) {
  return request.put(`goods/${data.id}/attributes`, data, { requestOptions })
}

// 更新商品的状态
export function updateGoodState(data?: any) {
  return request.put(`goods/id=${data.id}/state=${data.state}`, null, { requestOptions })
}

// 上传图片
export function uploadGoodsImage(data?: any) {
  return request.post('/uploads/images', data, { requestOptions })
}

// 富文本图片上传
export function uploadGoodsEditorImage(data?: any) {
  return request.post('/uploads/ueditor', data, { requestOptions })
}
